﻿@model Article
@{
    Layout = "~/Views/Shared/LS/_Layout.cshtml";

    var tags = ConvertHelper.StringToStringArray(ConvertHelper.ToString(Model.ExtField01).Replace("，", ","));

    var sql = StringHelper.FormatSql("SELECT top 3 *  FROM [cms].[Article] where id!='{0}' and  catalogIds like '%{1}%'", Model.Id, Model.CatalogId);

    for (int i = 0; i < tags.Length; i++)
    {
        if (i == 0)
        {
            sql += StringHelper.FormatSql(" and (ExtField01 like '%{0}%'", tags[i]);
        }

        if (i != 0)
        {
            sql += StringHelper.FormatSql(" or ExtField01 like '%{0}%'", tags[i]);
        }


        if (i == tags.Length - 1)
        {
            sql += ")";
        }
    }

    sql += " order by id desc";

    var hotArticles = IoCHeler.Resolve<IArticleAppService>().Query(sql).ToList();
    ViewBag.ShareTitle = Model.Title;
    ViewBag.ShareContent = Model.Summary;
}

@section Head{
    <meta name="description" content="@Model.Summary" />
    <meta name="referrer" content="never" />
}

<div class="content_detail clearfix">

    <div class="content_detail_left" >
        <div class="title">@Model.Title</div>
        <div class="part2">
            <a class="icon-user iconfont" href="#" target="_blank"> @Model.Author</a>
            <span class="icon-time iconfont"> @Model.PublishTime.GetValueOrDefault().ToString("yyyy-MM-dd")</span>
            <span class="iconfont icon-view" style="float:right;margin-right:20px"> <span style="color:#17abc1">@Model.ViewCount</span></span>
        </div>
        <div class="y_text2">

            <p>@Html.Raw(Model.Text)</p>
        </div>

        <div class="comment-post">
            <h3>评论：</h3>
            <input type="text" placeholder="您的大名" id="userName" maxlength="20" />
            <br />
            <textarea placeholder="您的见解" id="content"></textarea>
            <br />
            <button class="" id="btn-comment">提交评论</button>
        </div>
        <div id="comment-list">

        </div>


    </div>

    <div class="content_detail_right">
        <p>相关资讯</p>
        @foreach (var item in hotArticles)
        {
            <div class="a_img">
                <a href="?key=@item.Key&page=@Request["page"]"><span><img src="@item.TitleImageUrl" data-bd-imgshare-binded="1" /></span></a>
                <div class="title"><a href="?key=@item.Key&page=@Request["page"]">@item.Title</a></div>
            </div>
        }

    </div>
</div>

<div class="adlist_hide" style="display:none">
</div>

@section Foot{
<script>

        var queryString = function (name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regexS = "[\\?&]" + name + "=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location);
            if (results == null) {
                return "";
            } else {
                return decodeURIComponent(results[1].replace(/\+/g, " "));
            }
        }
        var key = queryString('key');
        var isSubmit = false;
        var Page = {
            getCommentList: function () {
                $.getJSON('/cms/Comments/read', {
                    articleId: '@(Model.Id)'
                }, function (data) {

                    var list = data.Data || [];
                    var h = '';
                    if (list.length > 0) {
                        $.each(list, function (i, item) {
                            h += '<div class="comment clearfix" ><div class="comment_right ">';
                            h += '<div><span>' + item.UserName + '</span> <span>' + item.CreateTime + '</span> </div>';
                            h += '<div>' + item.Content + '</div>';
                            h += '</div></div>';
                        });
                    } else {
                        h += '<div class="tip-null">暂无评论</div>';
                    }
                    $('#comment-list').html(h);
                });
            }
            , initPost: function () {

                $('#btn-comment').click(function () {
                    if (isSubmit) {
                        return false;
                    }
                    var userName = $('#userName').val().trim();
                    var content = $('#content').val().trim();
                    if (userName.length == 0) {
                        alert('输入姓名')
                        return false;
                    }
                    if (content.length == 0) {
                        alert('输入评论内容')
                        return false;
                    }
                    isSubmit = true;
                    $.post('/cms/Comments/CreateForPC', {
                        articleId: '@Model.Id'
                        , userName: userName
                        , content: content
                    }, function (data) {
                        isSubmit = false;
                        if (data && data.ErrorMessage=='ok') {
                            alert('评论成功');
                            $('#userName').val('');
                            $('#content').val('');
                        } else {
                            alert(data.message || '评论失败');
                        }
                    });
                })
            }
            , init: function () {
                Page.initPost();
                Page.getCommentList();
            }
        }
        Page.init();


</script>
}